#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2020 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

"""

"""

import sys


def my_read_line():
    # NOTE: 去掉换行符, 注意:但也会去除开头和末尾的空格(有时候可能不符合题意)
    return sys.stdin.readline().strip()

def read_ints():
    # s = raw_input()
    s = my_read_line()

    ints = list( map(int, s.split()) )
    return ints

def read_line():
    # s = raw_input()
    s = my_read_line()
    return s

# 1 + 2 + 3 + r

def sum_digit(o):
    s = 0
    for c in o:
        s += int(c)

    return s


def calc(s, d, r):
    # 计算最后一行起始索引
    last_e = int((r * (r+1)) / 2)
    last_b = last_e - (r - 1)

    sum = 0
    # 处理最后一行
    for i in range(last_b, last_e+1):
        n = s + d*(i-1)

        # n 转8进制
        # print("n is ", n)
        o = oct( n)[2:]

        # 计算这个数的各digit之和
        sum += sum_digit(o)

    # print("sum is ", sum)
    # 最后一行digit总和
    print(sum)

def form8_10(f8):
    return int( str(f8), 8 )

def main():
    for i in range(5):
        s8, d8, r = read_ints()
        s = form8_10(s8)
        d = form8_10(d8)


        calc(s, d, r)

if __name__ == "__main__":
    main()
